define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'amap/index' + location.search,
                    add_url: 'amap/add',
                    edit_url: 'amap/edit',
                    // del_url: 'amap/del',
                    multi_url: 'amap/multi',
                    import_url: 'amap/import',
                    table: 'amap',
                },
                showExport:false
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: true,
                visible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                searchFormVisible:true,
                showExport: false,
                columns: [
                    [
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'level', title: '级别', formatter: Table.api.formatter.flag, searchList: {1:"省、直辖市", 2:"市", 3: "区、县"}},
                        {field: 'is_hot', title: '是否热门城市',formatter: Table.api.formatter.toggle, searchList: {1: '是', 0: '否'}},
                        {field: 'code', title: __('Code'), operate: false},
                        {field: 'province', title: '省份编号', operate: false},
                        {field: 'city', title: '城市编号', operate: false},
                        {field: 'district', title: '区县编号', operate: false},
                        {field: 'province_name', title: '省份名称', operate: 'LIKE'},
                        {field: 'city_name', title: '城市名称', operate: 'LIKE'},
                        {field: 'district_name', title: '区县名称', operate: 'LIKE'},
                        {field: 'province_short_name', title: '省份简称', operate: false},
                        {field: 'city_short_name', title: '城市简称', operate: false},
                        {field: 'district_short_name', title: '区县简称', operate: false},
                        {field: 'pinyin', title: '拼音', operate: false},
                        {field: 'pinyin_tone', title: __('Pinyin_tone'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
